/**
 * 
 */
package utilities;

import java.io.BufferedOutputStream;
import java.io.IOException;
import java.util.Enumeration;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * @author Stefan
 * 
 */
public class ServletUtilities {
	private static final Log log = LogFactory.getLog(ServletUtilities.class);
	/**
	 * writes the parameters of a {@link HttpServletRequest} to an
	 * {@link HttpServletResponse}.
	 * 
	 * @param req
	 * @param resp
	 * @throws IOException
	 */
	public static void forwardRequestParameters(HttpServletRequest req,
			HttpServletResponse resp) throws IOException {
		log.trace("forwardRequestParameters " + req.getMethod() + "REQUEST "+req.getRequestURL());
		Enumeration<String> parameterNames = req.getParameterNames();
		BufferedOutputStream out = new BufferedOutputStream(resp
				.getOutputStream());
		while (parameterNames.hasMoreElements()) {
			String name = parameterNames.nextElement();
			String value = req.getParameter(name);
			out.write((name + ":" + value +"\n").getBytes());
		}

		out.flush();
		out.close();

	}
}
